# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=apt
pkgver=2.9.10
pkgrel=0
pkgdesc="APT package management tool"
url="https://salsa.debian.org/apt-team/apt"
arch="all"
license="GPL-2.0-or-later"
depends="
	debian-archive-keyring
	dpkg
	"
makedepends="
	bzip2-dev
	db-dev
	cmake
	dpkg-dev
	eudev-dev
	gettext-dev
	gnutls-dev
	libgcrypt-dev
	lz4-dev
	samurai
	triehash
	xxhash-dev
	xz-dev
	zlib-dev
	zstd-dev
	"
checkdepends="gtest-dev"
install="$pkgname.pre-install"
pkgusers="_apt"
pkggroups="_apt"
subpackages="
	$pkgname-dev
	$pkgname-libs
	$pkgname-lang
	$pkgname-bash-completion
	"
source="https://salsa.debian.org/apt-team/apt/-/archive/$pkgver/apt-$pkgver.tar.bz2
	fix-basename.patch
	"
options="!check" # todo

build() {
	cmake -B build -G Ninja -Wno-dev \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_INSTALL_LIBEXECDIR=lib \
		-DCURRENT_VENDOR=debian \
		-DUSE_NLS=ON \
		-DUSE_SYSTEM_APTPKG=OFF \
		-DWITH_DOC=OFF \
		-DWITH_TESTS="$(want_check && echo ON || echo OFF)"
	cmake --build build
}

check() {
	ctest --test-dir build --output-on-failure
}

dev() {
	default_dev

	mv -v "$subpkgdir"/usr/bin/apt-config "$pkgdir"/usr/bin/
	rmdir -v "$subpkgdir"/usr/bin
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	cd "$pkgdir"
	chown -Rc _apt:_apt \
		etc/apt \
		var/cache/apt \
		var/lib/apt \
		var/log/apt
}

sha512sums="
8b8d7a7c2266e94288016ba5128a8c4286c365df4305cff7a9f763765d882b7a04be9e7e831a06a04a1e52c286387be1e8179d7000ff57f28aba7e164f138c93  apt-2.9.10.tar.bz2
27d7e1516915bbae025c4c943c7427421662e7c3bee8f1821565ac3cd823e8a823c4ac99efb9cc9a27e338c73b49e2628f0a88c5c2c1d2e935b1c89b9209d18c  fix-basename.patch
"
